package utils

import (
	"os"
	"path/filepath"

	"github.com/zeromicro/go-zero/core/logx"
)

type objPath struct {
	ObjPath string
}

// 获取当前项目路径
func getObjPwd() string {
	pwd, err := os.Getwd()
	if err != nil {
		logx.Error(err.Error())
		return err.Error()
	}
	parentDir := filepath.Dir(pwd)
	subPath := filepath.Dir(parentDir)
	objPath := filepath.Dir(subPath)
	return objPath
}

// filnames 传入["static", "index.html", ...]
func (p objPath) GetStaticPwd(filenames []string) string {
	filenames = append([]string{p.ObjPath, "static"}, filenames...)
	return filepath.Join(filenames...)
}

// 拼接其他文件夹的文件路径
func (p objPath) GetOrderFilePath(filenames []string) string {
	filenames = append([]string{p.ObjPath}, filenames...)
	return filepath.Join(filenames...)
}

func newObjPath() *objPath {
	logx.Info("实例化path")
	return &objPath{
		ObjPath: getObjPwd(),
	}
}
